added the last functons, bug fixes, added timer for several functions in
middlware