Code refactoring & cleanup.