fixed tests & small logic error