bugfixes & tiny optimizations