Correction of issue 509 in the original fork with tests.
Created originally on Bitbucket by khchine5 (Khchine Hamza)
Was already merged in Bitbucket before import, marked as merged by the import user
Correction of issue 509 in the original fork with tests.