Removed comments and refactored speed detection.