Arrange the code

Change variable names and arrange some code