Refactored: Duplicate code moved into separate files.