Added null-check for retrieving user by username. It was doing unnecessary db lookups.