Taking out some stuff to create a new class

Added a new class to use a DRY (Don’t Repeat Yourself) approach. I
don’t think it will affect the functionality too much, but I’m not able
to debug ATM.