significant refactoring toward generalized usage. refence graph test added