fixed some logical issue