Some clean up changes and new calculation of timeoutvalue