big code cleanup