Move into module and separate API and CLI