Fixes various issues with debug scoping and implements stack.