Added exception handling so file errors don't kill the thread