More code refactoring/cleanup.