Trying to sort out database