Refactoring

Extract functions.