BAM-138: Corrected the code to avoid NPE in case query string is not present in previous URL.