Mostly refactored and mostly working.