Improved class functions with hasattr and clean up scrap code

This is necessary to use one function defined at the class level in multiple subclasses even if the subclasses have differrent attributes; additionally since the code is function it was good to clean up.