code cleanup and report writing