lab 7 slightly refactored