Refactor common.cpp and document accordingly