add db thread, cleanup
small changes
split in library
cleanup