check if array-like before attempting flatten