added errordetector middleware, cleanup