snad_to_grid function optimalized