Fixes issue #998.

Fixes multiple issues with the way PR #997 was implemented.