Added optional error callback