added explanation in code