Investor protection and optimal contracts under risk aversion and costly state verification