rework, unit tests and docs