Refactored hw3