Refactor some codes.

Refactor some codes. (Chapter 8 exercises in Ruby on Rails Tutorial)