Mujir/Neha - added some defensive checks.