fix null pointer when added variable