Repackaged API and cleaned up code.