Code improvement for #197

Improved code from pull request #197 as suggested by @stanio.

You certainly do learn something new everyday.