Random refactoring

See commits.