A sleep monitoring and maintaining apparatus comprising an airflow sensor for detecting breathing waveform shapes of a patient, a patient gas delivery device having an adjustable gas pressure delivery level, and a controller in communication with the airflow sensor and the gas delivery device, the controller being adapted to: monitor the detected breathing waveform shape while the gas pressure delivering level is ramped up; and to: apply an adaptive algorithm for detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal wherein the variation detected by the algorithm is associated with standard empirical data threshold settings or with available previous patient data, including a specific airflow shape characteristics or various threshold indications, thus indicating the probable onset of arousal, characterised in that the controller is further adapted to in response to said detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, maintain or reduce the gas pressure delivery level to avoid the probable onset of arousal until the monitored detected breathing waveform shape indicates the patient is in a deeper level of sleep than indicated by the detected variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, enabling continued ramping up of the gas pressure delivery level. monitor the detected breathing waveform shape while the gas pressure delivering level is ramped up; and to: apply an adaptive algorithm for detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal wherein the variation detected by the algorithm is associated with standard empirical data threshold settings or with available previous patient data, including a specific airflow shape characteristics or various threshold indications, thus indicating the probable onset of arousal, characterised in that the controller is further adapted to in response to said detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, maintain or reduce the gas pressure delivery level to avoid the probable onset of arousal until the monitored detected breathing waveform shape indicates the patient is in a deeper level of sleep than indicated by the detected variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, enabling continued ramping up of the gas pressure delivery level. apply an adaptive algorithm for detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal wherein the variation detected by the algorithm is associated with standard empirical data threshold settings or with available previous patient data, including a specific airflow shape characteristics or various threshold indications, thus indicating the probable onset of arousal, characterised in that the controller is further adapted to in response to said detecting variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, maintain or reduce the gas pressure delivery level to avoid the probable onset of arousal until the monitored detected breathing waveform shape indicates the patient is in a deeper level of sleep than indicated by the detected variation in the monitored detected breathing waveform shape that is indicative of a probable onset of arousal, enabling continued ramping up of the gas pressure delivery level.