Heavy code cleanup