Added a possible null pointer exception protection.