Refactored into classes
cleaned up an error