cleaned up code and added comments, also modified registration code to create a new user automatically without going through the registration page.