better version of #527

closes #527