Solved the issue of script stopping after certain number of records.