Refactored code (added Classes for validation and logging)