Moved code into a class; Refactored