Cleaned up and refactored application setup code