significant code cleanup