reward function a la branavan
merged