Optimize code a fair bit