Bugfix pull 358

Fixes issue raised in pull #358.

Also does some tidy up around it.