Completed refactoring Al's code.