refactored into two classes
implemented classes and recursive input