introduced meshgrid for improved efficiency