functions separated out to cut out complexity