Manually updated with upstream changes