Massive code cleanup