clean up the code to make it more tight and reasonable