computing expectation correctly