Fixed content mangling bugs. Added more tests.