File sorting and cleanup