restructure and more flask conversions