Refectored code and created a class function.