ISLANDORA-32 Moved decision-making code into a function.