Some fixes & optimizations