Minor improvement and bug fix to rename function