improved db write/read