Set the state on newly added elements to the state of the parent. Add some debug info and do some cleanups