Fixes #505 and closes #506