Refactor to the main API classes to prepare for unit testing.