preparation for parametrized export

+ some fixes in ORM
fixing bugs from previous commit