Debugging - patch to fix buffer read logic (bad use of "hasRemaining").