append function logic