template metaprogramming tools for type safety; fixed type safety issues