some explanation in comments added