lot of refactoring... to make classes more flexible