ref #206: move logic out of pt into py.