refactored to make more readable