converted C++ code into fantom. probably useful

probably not.. need to go through dr clarke's stuff