refactored main, added flask.ext.mongoengine and updated req
small changes, more pythonic