Fixes #218 @adrian17 did all the work for this fix.
Merge pull request #255 from duncanspumpkin/fix_218

Fixes #218 @adrian17 did all the work for this fix.