broke things up into discrete functions