Changed the way max columns are calculated