Better function for converting to Array