added directory existance checking