Much needed code cleanup