extensive refactoring
.