Some code clean-up and minor bug-fixing.