fix based on patch by Julien Rivaud (frnchfrgg), but re-written a bit differently not to be operator specific.