Refactored detectOS() to simplify it