Improving detached head implementation