Refactoring. Cleanup.
Added changes related to coming API changes.