Yes, it can be done but I didn't want the ```elseif (is_string($fields))``` to start with the failed (negated) previous test ```!(is_array($fields) && count($fields) === 1) && is_string($fields)```, because It would lead to a not so self explanatory code and difficult to maintain later, instead it is ```!is_array($fields) && is_string($fields)```.

I feel the same way, it should be better contained inside a function. But as I stated earlier, most of the ```$quote``` block code should be there to avoid writing to the cache when the fields end up being the same.