Backported changes from RCPTT

Last RCPTT commit: 2f5d7c54455b53e0a3e83acd4f40ed1627a8e4ee