Big reorg. to follow Flask best practices