Move common functionality into a class