Massive changes, but I'm pretty sure it's working correctly now.