[COOK-3357] Refactor and add tests