Improvements for performance-sensitive code; put time-related code into extra functions in places