refactored app code