Rewrite to something actually working and sane that also prevents key
conflicts