finished write logic