trying to work out the logic in a couple functions