updated middleware to use new api