fix grid logic