Various bug fixes for regression tests