These 2 new methods are rewrites by me of the rb patch - if there are issues, compare these two commits (cherry picked from commit 18ed8d2f)