One way to fix marching squares

One possible way to fix the code;
I am still open for other options.