Fixes #342 and #339