refactored buggy trustchain building, fixed refcount bug