fixed some logic issue
I think I fixed merge conflict