Fix for #590 and #591