Refactor regist code