Breaking out logic into functions