changed timeout calculation to address overflow