Author: holananz - backported by krEsz