Refactoring. General API code cleanup.