Refactored to more object oriented approach