Use metaprogramming to remove code smell. Still hacky.