Massive clustefuck of changes. Kinda works now, still throws random exceptions.