code cleanup and formatting