Replaced some verbose matches with foreach