merged some refactoring back to the v1.54 branch