Add state funtions to WriteFile, Fix driver