Fixed the remaining linker errors and found some nasty runtime bugs