Modify code for cleanup