add saving database to device and few fixes