removed unused code
removed repeating writes