fixed invalid casting
Fixed selection of existing database