Refactored according flask recipe