Refactored to modularize programs.