fixed memory leak & errors on db creation