Added sanitizing of user and cleaned up some code