Fix encoding error with UTF-8

There was an issue with encoding so I've implemented the codecs.open
method to open the file as UTF-8 and ignore errors. Not sure if this is
best but it gets around the issue causing the fatal error. Also cleaned
up error output.