fix endRun and endJob functions