Made register/reset more robust