refactored assignment 4