fixed file open calls, fix ampersand and insertWithContent bugs