Completed functionality of avoiding invalid files.
Working Collapsing mechanism for all files.