Type-level templates, fixes, cleanup