Refactored to remove excess metaprogramming