Some clean up, small error fixes and encoding changes