Major refactor. Remove most older code.