refactoring classes; many improvements