Adds better error handling and UTF-8 file encoding