optimize code for bulkapi