Lot of refactoring