Added better path checking