refactor flask server