Implemented app-side timeout. Refactoring.