fixes, refactor and alloc support for dictionary