optimization and apnea detection