add function to attach detach database

add cleanup function
we now have a working prototype