Refactored for tests after mega-merge