Fix possible index out of bounds error in handler test