Speed up and null pointer issue fix