Update flask app and fixed variable scope