removed redundant code
reorganized into one double loop
fixed werid diagonal sets issue
so close