david and lee's modifications added
added mike s, david and lee's solutions
added comments to describe various code blocks