added if statement to avoid null pointer on insert