Structure and ionization potential of Hf III and Hf IV