Refactor code out into a class