numerous bug fixes