Code cleanups & optimizations

Code cleanups & optimizations