Some ground work
Not defensive enough in middleware