Fixes and tested in 3.9