Refactor to a more object oriented approach