massive code cleanup