use readdir instead of hacked thing