Some refactoring as Kevin Liang requested.