Introduce batch process to prevent memory issues

I came up with some issues for big files running on limited environment. So here is my fix to prevent issues with memory.