Optimizations & bug fixes