Helper function for appending elements. Prelim work on history