Refactored the stuff to use classes.