Fix logic error, possible concurrent modification issue