Fixed encoding mishaps. Adjusted tests.

Fixed encoding problems I bumped into and saw over different issues here.

/cc #319 #460 #466 #496