checks for parent id == -1 now instead of p_id == agent_id
removes tmp files even on failure
added guard to check for parent id in invariants
a cleaner message