numerous bug fixes
merging conflicts