try and catch for null pointerexceptions are added to retrieve and add