Remove isValid check (it's too slow). Additional optimizations.