refactoring: getting rid of complicated template class hierarchy