Fix logic error