Core rewrite: Some tests, some fixes.