Refactor and add support for days

Break out some of the logic into it's own method and add support for
history. Instead of having a hardcoded value for the number of days to
look back (2 days), add an argument.