Programming is about discovery, not invention.

Code review

  1. Find all loops.
  2. Replace all the loops with appropriate algorithms.
  3. Always return all the useful information from your algorithms.
  4. Make them general.