improved cell number logic