Some minor bug fixes and checks for null.