Issue #24: refactor of C++ code to separate Python-logic from rank/unrank impl.
Issue #24: general cleanup of code