widely refactored