improve loop efficiency