fix bug discovered by Unit tests