Better debug support and fixed bugs in scoped_* when the ptr given is the same as the one held