Fixes #480 and #506