Refactor PID assignment