first working implementation after refactoring