refactored for error handling and hourly runs