Major refactor

major refactor