Mostly re-factored.