Completed timeout calculation, added a debug print function.