bug fixes & optimizations