converted unpure function ifa_detect to two pure functions