refactor equals() method to compare class; add failed case of tail recursions