Several major fixes