Move closeDatabase to database.cpp, clean up a bit