Revert "Refactored some code"

This reverts commit cbc44e37880ca3ee469338b3b08f51ec0c7d339a.
Revert "Revert "Refactored some code""

This reverts commit b1047255a6b803a631bbac42c27b78af582c033a.
Fixed issue w/ Flask.