Sid's HW2 solution