flask refactor