refactored with classes and main