refactor codes and add hard-delete test.