major changes: fix inner classes, ns mapping, need tests!