Switched loop in custom handler to use do...while syntax