Fixed problems discovered by looking at example code. Still untested.

Signed-off-by: Xiaomao Chen <xiaomao5@live.com>