refactored hw1-part4