added writeList() function