improved call-back logic and error handling