improve verify function