restructure insertLastElement to try to circumvent Safari Mobile 6 errors