Test nested types. Fix some bugs in implementation