clean up middleware source codes