Function to fill grid