Completed refactoring of upper half.