Added accidentally removed fg.close(), tidied appends