Split database package into multiple files.
Add a semaphore to locking DB functions.