Clean up code and separate API and rename code