Refactored program logic in to a class