move detect_os to a function