a more object-oriented approach, still too messy