Fixes #939, @lefticus can you code review this?

@DavidGoldwasser Can you merge into develop and test this out tomorrow?