code cleanup and improvements