Fix programming mistakes and compiler warnings concerning class Grid