Munge the code a bit, use some higher level stuff
Merge pull request #1 from barneydesmond/master

Used some slightly higher level code and a loop - Thanks Barney!