Made optimizations to code