Fixed issues #2 and #3

Using the same code as to deal with the directories