Fix crash bug due to not keeping database around