Made db a global variable so same connection can be used all over.