Fixed login and application

This pull request fixes the bugs in the login and the application logic.