This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
i'd also suggest you learn to use the 'code' tags. When pasting source, just click the little "code" button and the tags will auto-populate. then paste your source code between them. It preserves the indentation and makes reading what you have MUCH easier.
I'd add them to your post, but you don't have proper indentation anyway, so it won't matter.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors