STS-3743: adding extra guards to prevent NPE