Enhancement and refactoring

Changes are grouped by commits.