XD-374 Code review + add tests