some fixes & optimizations