Refactor to clean up API and make more extensible