Added timeout loop and changed directory of tempfile