made algorithm easier to understand