Converted main logic to class