Fixed bug in setting endtime