possibly safer batch process and fixed logging