Some major changes:
- fixed add to work with directories
- factored out constraints as invariant, added an invariant preservation check