Added logic to handle null totalDue