Fixes #258, #254 and #257