Fixed some logic error