Refactored the main script into multiple files.