first working version while refactoring