Added grid references, some fixes. Code simplification and comments