Bug fixes from previous merge