improved evaluate function