Corrected append to list function