Refactored os detection