Improvements for several valid() functions

So far only CPU formats, some of these changes need to be applied to OpenCL and CUDA formats.
May be I'll find time for it next week