Refactoring to make use of Flask helper methods