porting over some internal changes