Issue #509

Fixes for #509