fix defer
fix when empty database