Small refactors and API fixes