serious code cleanup