refactor by following ruby style guild and TA's opinion