Improved implementation for case-insensitive environments.