Refactor/fix changes introduced in commit ad88c

See commit messages / corresponding issues for details.