fix most of the problems in #2590