Refactorized code into classes