refactored for Flask microframework