added ternary operator to avoid NullPointerException if duration is null