added more assertion checking.