refactored into classes