few optimizations & cleanups