Refactored context path removal code to a static method (#731)