Added array with variable length to store the result, TODO: deal with free()