Refactoring code to fit into a classbased structure for easier extending.