better solution for exercise 6: make it modular