Fix for issue #496

see my comment in the issue for explaining the bug