Refactoring HW1 after watching lecture 4