Switch match function to faster `while` construct