some bugfixes in optimization