Move pid checking/creation to middleware layer

see title (y) :neckbeard: