Revert "inverted logic bug"

This reverts commit 3277f9c47dd815427c7567de374da523a489ef04.
fixed large number of bugs