added directory checking