Numerous bug fixs