Made little optimizations to code