Overhaul Flask implementation