Adds Vlad's patch from issue #709