refactor delete query