Fully rework of code structure and first unit tests