refactored some repeated code to parent class