working version
big refactoring with new logic