some bugfixes & optimizations