Fix for files with lots of layers

Copied the logic from organize library that dealt with large frame
counts causing the script to stall