Some miscellanous and minor refactoring.