Refactoring: extracted some functions.