Unravelling and controlling hidden imprint fields in ferroelectric capacitors