OK. To me, this bit of your formula seems problematic:

D14-IF(C14<G$9,G$9,C14)

C14 is 0:00. G9 is 06:00. D14 is 05:00.

D14-G9 gives a negative number.