Added conditional end time population to avoid an error message in undefined cases.