massive rewrite, started using flask classy