refactor to use a more object-oriented approach