remove redundant data structure
more refactoring and fixes
Fixed conflicts