Much faster implementation for common cases.