fix bugs regrading to logic errors