Fix upstream merge and tests