Added class for polymorphic tree management, changed id to pk in some places.