Fixed bug with opening database