Rather extensive updates

Many changes and additions incompatible with older versions of flask, feel free to do what you want with this.