refine and fix function appendItem