refactored hw1 part3