refactor ignore case code to handle all precedence scenarios