Contribution by Paul Richards
C++ source code