Rewrote pid assignment.  Fixes #13