refractored flask to mysql