secondary bugfixing + serious optimization