improved column calculation in grid layout