converted code to be class-based