Refactor to use a separate class instead of all in a main class