added more defensive condition checking to paths