Lab 3 -- refactored