Fix issue #781

To fix issue #781.

Was a quick fix for me haven't seen any issues with the change.
But someone who knows the code base better may be able to spot issues.