Moved command to delete temp file to expect script; Various bug fixes