Cleanup and add comments documenting main API