Fix issues with sorting and createDirectory