Generalised code for adding multiple elements.