optimize carousel test code