More functional refactoring
Merges