Adding temp files and error handling