Made some fixes and improvements to C++ version

- compiles under MSVC
- fixed a bug in pickLevelByCriteria
- about 150ms faster for me

Slightly more details in 232a2da2e76ab1dbbe5ae75eabad7a031bc1ad10