restructured middleware handlers, added user model tests