Replaced mgrid with meshgrid, and some cosmetic changes.