refactored for brevity