Fix timeout seconds calculation bug, and minor cleanup.