Added a number of general bug fixes from master branch to base branch.