Added possibility to chose type of output: array, object, string