a big refactoring