refactored use of of classes for efficiency