Tidied up formatting, removed whitespace and checked the user model was not empty before trying to get its ID for setting a session key