REFACTORED: moved core functionality to class