clean up the code
fix fatal error in rule exchange