Some refactorings made for better organization.