Bug fix

Numerous fixes