Major refactor
merged with refactor