quite a arefactoring... still lot to do