The juvenile court had discretion to extend services beyond six months where the parent was about to be released from prison. The incarcerated father sought writ relief from an order terminating his services after six months and setting a 366.26 hearing as to his daughter. He contended that the juvenile court erred in believing it had no discretion to continue services and in finding that reasonable services had been provided. The department and minor’s counsel agreed that there would be no detriment to the minor from continuation of services and did not oppose the requested relief, but argued that reasonable services had been provided. The appellate court granted the writ and ordered the trial court to reconsider continuing services. The trial court believed it had no discretion to continue services if the father did not satisfy all three criteria found in section 366.21, subdivision (g)(1)(A)-(C). Since the father was incarcerated, he was unable to have consistent contact with his daughter, as was required by that section. Although the court did not err in considering those factors, it erred in believing that it had no discretion to consider services if the factors were not met. The court’s failure to properly exercise its discretion prejudiced the father because other factors should have been considered, such as the child’s safe placement with her grandparents, the father’s shortly expected release from prison, and his sincere desire to reunify with his daughter.