Fixed #590 (untested because I'm in a hurry)