Separated two tasks that cause race conditions and multiple callbacks