added pid-level heartbeat. Code cleanup.