Further improvements based on Steven's fixes.
Use long primitives for time calculation.