lots of refactoring..