major bugfix, performance improvements