fix #597 bug spotted by @jvasileff