Some cleanup and refactoring...