Code refactoring.
part of #68.