Moved isValidKey function into a separate module.