Improve code for issue #322.