fix inversion, simplify, remove templates