various bug fixes