code cleanup into functions and added a name change check patch