write function causing problems, commented out