Optimize code