reduced encodings in 'writefile'
improved opening file in 'writefile'
added more readability in 'writefile'