refactor flask