Database layer updates.

Signed-off-by: enyst <engel.nyst@gmail.com>
Remove useless globals. Database layer updates.

Signed-off-by: enyst <engel.nyst@gmail.com>