Fixing issue #6

I believe this fixes issue #6.  There could obviously be some improvements, but this should work well enough for the time being.