Refactor app architecture