Put grid logic into new class in library.

(OpenGL related code still needs to be handled in the interface)