backported more chnages and debugging