Helper functions and the lap-count function