Couple database optimizations and fixed a couple typos in database
retrieval