use array_shift before the foreach to avoid this nested if, it will make the method look cleaner