Refactor register user logic