Initial refactoring

Some refactorings made according to comments to https://jira.ez.no/browse/EZP-21166
@dpobel : review is welcome.