Refactored "database.cpp"

Minor formatting changes. I made the termination conditions more
explicit by adding "else" branches.