added tolerance as parameter