applied Matthias Christian Ott's sanity fixes (thanks a lot!)