Many bug fixes