Patch for issue #299 (thanks to @eltjpm)