moved logic to grid()