fix issue with writing into subdirectories