Applying bigianb's patch as described in issue #789

I am not sure if links work through titles, this is in reference to issue #789 . It fixed master for me as well as bigianb.