Refactor to be less metaprogrammatic. Remove type casting.