detached handling refactor