refactored for clarity