Optimization

Added some simple optimizations to certain code segments.