Fixed some issues identified by assertion.