Added buffer clears to fix invalid input hang.