Simplified OS version check and fixed substr error.