restructure to use classes and some other minor changes