[fix] Fixes of bug revealed by unit tests.