Generify classes

This was mostly achieved automatically using static analysis tools.