Use detect module. Remove duplicate funtions.