Some bugfixes. Still not ready yet.