Fix issue when copying or moving folders

Also remove unused code.