Make autodetect of path more stable