Refactored Helper for Api Key validation