Fix for #565

See commits messages