Handles directories properly