Optimize and defragment code