Bug fixes, mainly in tests