Fixes logic error