Increasing max sorted segments to optimize limit back to 40
Adding null checks to avoid NPE in merging