fix keyIsInvalid and keyErrorMessage methods