Fixes #470 and #508