Misc changes. Refactoring.