Compacting and optimizing code