extract load from middleware, add some tests