Fix entity duplication once and for all (WIP)

It works now.