EZP-22402: Refactored aliases handling

> Fixes http://jira.ez.no/browse/EZP-22402

See #792 for description.

### Todo
- [x] Squash commits (keep tests in separate commit)