Fix for #19 + tests (spacebark beat me to it :D )

spacebark beat me to it, but here is my fix anyway (it's close to spacebark's) + test for when a directory is replaced by a file and vice-versa.