fixed crashes with empty database