re-structured code to use c++ classes