Finally fixed temp file bug