Recover some changes and add some fixes