Fix major logic error