Better fix for issue #183

The former patch was too local; this one integrates better with the structure of the code.