Refactored duplicate code
Closed #28
Fixed minor bug when changing user name fails