passes valgrind. must investigate some sqlite leaks