Refactoring complete

Class version all done. Final version under current code.