improved folder detection