Refactor and add test for saveBarn