Changes to internal API and some refactoring to returned object