changed some searching logic