refactor of flask code to clean up
merge