Better fix for issue #183

The former patch was too local; this one integrates better with the structure of the code.
Merge pull request #281 from pgimeno/cpu100percentfix

Better fix for issue #183