Some refactoring and a fix in regiter/5