Added append code - fixed some bugs