Fix registration process

Scopes of various variables was undefined