added null check for duration