fix bug due to a closure on ready callback