Better fix for logic error