the logic made more accurate