Refactor and tests for Application