Added optional onError handler.
0.4.0