refactor fillGrid function