Code cleanup. Added grid randomizing.