Merged finalization with squashed refactoring of test classes

Merged #216 with a squashed #217. @SamoylovMD @vkostyukov What do you guys think?