added checks in case data is empty, fixed some bugs with establishing relationships when creating objects