Bug fix inner loop j
runable version, still not good