big refactoring. stable