cleaning up api and xhr middleware