fix one logic error and there is another one but i have no ididea now