New logic
Some refactoring