Explicitly close database statements when done with them

This intends to resolve #288