small refactoring
using metaprogramming to keep it DRY