Tweak core.serialize

This adds proper support for nested tables and improves performance a bit.