Improve speed and lags

Instead of leaving the database open, until the app is disposed, I'm
opening in when I need it and after the operation is finished I close
it.