added comment to make the logic more clear