Added comments. Improved grid generation.