refactored for simplicity