Final fixes for detached head mode (93% cov against 94% cov in branch mode)