Adding some bug fixes from the main branch.