change loop to built-in function for performance