first working version using initial grid given by array of keys