Sorted out database issues