More Flask improvements and refactorings