Code cleanups and temp file removal