Huge refactoring of internal code to make API object