Fixes and improves debug loop