fixed a bug where callback was called 2 times in case of error