Fixed format selection algorithm

It was failing in last version. Simple fix.