Sync with R's code