Fixed variable scoping issue which can lead to out of memory error.
Merge pull request #9 from shaunhardy/master

Fixed variable scoping issue which can lead to out of memory error.