Fix for "cannot convert circular structure to json"