Replaced duplication sen *eenth functions with more metaprogramming