refactored fix for potential denial of service attack