Add update register and clean some code