writing and reading functional