Unit-tests. Logic fixes according to found mistakes.