1) Added functionality to register user
2) Cleaned up duplicate code