Some code refactoring, and some minor UI changes.