some refactoring to prepare for #334
some tests changed due to #334
fix #334