Refactor app js