Updated to match Alex's solution