fixed bugs noted by diantahoc, added missing conditional in BSD section of detect_res