Database finally working properly