add constraints, change relations logic