several important bug fixes