Fixed authentication bug in sign up

Fixed authentication bug in sign up and reorganized sign up code to
prevent unexpected bugs