Fix bug witch check algorithm