add error handling and other counting