issue #586 + fixes to issue #613