optimal solution for appending