Improved performance for large libraries with xrange