refactored for performance