Refactored for cleaner source code.