Merged Adrian's fix for issue #164