null-pointer exception error fixed

edit function insert to prevent null pointer exception