refactored _prepare_grid