Restructured to work with flask