typos

only visible with utf-8
some more checks on arrays to avoid warnings

bad arguments for  'foreach' ( array was null)