substantial refactoring of os_check function and related conditionals