cleanup middlewre