Fix running time logic.
Clean up code and fix running time logic.