Massive Refactor and new functionality