Added checks for null values preventing null pointer exceptions.