Move metaprogramming to a function