Other bug fixes; code clean-up