use templating to simplify metatable creation