cleaned up login to remove duplicate code