Major refactor. Currently working but long way to go on cleanup