refactor main flask app