Refactoring and beautify codes.