Bug fixes from Adam