Fixes #538, following @tilgovi's instructions